package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* MineView
* */
class MineView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeJoin = Paint.Join.ROUND
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_23C2F3)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            save()
            translate(cx, cy)

            mPaint0.strokeWidth = (cx / 18).coerceAtLeast(minStrokeWidth)
            drawRect(
                -cx * 3 / 5 - cx / 10,
                -cy * 2 / 5 - cy / 10,
                cy * 3 / 5 + cx / 10,
                cy * 4 / 5 + cy / 10,
                mPaint0
            )

            drawLine(
                -cx / 4,
                -cy / 4 + cy / 5,
                -cx / 4,
                cy / 4 + cy / 5,
                mPaint0
            )

            drawLine(
                cx / 4,
                -cy / 4 + cy / 5,
                cx / 4,
                cy / 4 + cy / 5,
                mPaint0
            )

            drawLine(
                -cx / 2 - cx / 20,
                -cy * 5 / 6 + cy / 20,
                -cx / 4,
                -cy * 2 / 5 - cy / 10,
                mPaint0
            )

            drawLine(
                cx / 2 + cx / 20,
                -cy * 5 / 6 + cy / 20,
                cx / 4,
                -cy * 2 / 5 - cy / 10,
                mPaint0
            )

            restore()
        }
    }
}